class Material < ActiveRecord::Base
  
  belongs_to :factory
  
  validates :code, :name, :factory_id, :presence => true
  validates :code, :name, :uniqueness => true

  scope :visible, where('status = ?','visible')
  
  def full_name
    "#{factory.name}-#{name}-#{code}"
  end
  
  def visible!
    update_attribute :status, 'visible'
  end

  def hidden!
    update_attribute :status, 'hidden'
  end

  def status
    ActiveSupport::StringInquirer.new(self[:status])
  end
end
